<template>
  <div style="padding: 10px 2px">
    <!-- <div class="txt-box">
      <div class="left">系统名称:</div>
      <div class="right">馈电认证子系统前端控制设备</div>
    </div> -->

    <h3 style="margin: 10px auto; text-align: center">设备监控状态信息</h3>
    选择设备：<a-select v-model="selectDevice" style="width: 320px" @change="handleChange">
      <a-select-option v-for="item in deviceList" :key="item.topologyInstId" :value="item.topologyInstId">
        {{ item.name }}({{ item.deviceId }})
      </a-select-option>
    </a-select>

    <a-collapse accordion v-model="activeKey">
      <a-collapse-panel key="1" header="设备信息">
        <a-descriptions title="" bordered size="small" :column="1">
          <a-descriptions-item label="设备id"> {{ deviceData.deviceId }} </a-descriptions-item>
          <a-descriptions-item label="设备ip"> {{ deviceData.ip }} </a-descriptions-item>
          <a-descriptions-item label="设备名称"> {{ deviceData.name }} </a-descriptions-item>
          <a-descriptions-item label="设备类型"> {{ deviceData.type }} </a-descriptions-item>
          <a-descriptions-item label="设备端口"> {{ deviceData.port }} </a-descriptions-item>
          <a-descriptions-item label="本机端口"> {{ deviceData.localPort }} </a-descriptions-item>
          <a-descriptions-item label="所属单位"> {{ deviceData.departments }} </a-descriptions-item>
          <a-descriptions-item label="位置信息"> {{ deviceData.position }} </a-descriptions-item>
          <a-descriptions-item label="设备生产商"> {{ deviceData.manufacturer }} </a-descriptions-item>
        </a-descriptions>
      </a-collapse-panel>
      <a-collapse-panel key="2" header="工作上报状态参数">
               <a-form-model
          :model="form"
          :label-col="labelCol"
          :wrapper-col="wrapperCol"
          v-if="selectDevice.includes('BCode')"
        >
          <div v-if="false" style="width: 100%; height: 340px; overflow-y: scroll">
            <a-row style="">
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="设备序列号">
                    <a-input v-model="form.workingData1" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="电压">
                    <div style="display: flex; align-items: center">
                      <a-input style="width: 100%" v-model="form.workingData2" suffix="V" />
                      <!-- <span> V </span> -->
                    </div>
                  </a-form-model-item>
                </a-col>
              </a-row>

              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行接收功率">
                    <a-input v-model="form.workingData4" suffix="dBm" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行信噪比">
                    <a-input v-model="form.workingData5" suffix="dB" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行速率">
                    <a-input v-model="form.workingData6" suffix="bps" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行 Eb/N0">
                    <a-input v-model="form.workingData7" suffix="dB" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行自动调制编码">
                    <a-input v-model="form.workingData3" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行载波同步">
                    <a-input v-model="form.workingData8" />
                  </a-form-model-item>
                </a-col>
              </a-row>
            </a-row>
            <a-row style="">
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行位同步">
                    <a-input v-model="form.workingData9" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行帧同步">
                    <a-input v-model="form.workingData10" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行链路状态">
                    <a-input v-model="form.workingData11" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="上行发送帧计数">
                    <a-input v-model="form.workingData12" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行接收帧计数">
                    <a-input v-model="form.workingData13" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="接收协议网关帧计数">
                    <a-input v-model="form.workingData14" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="发射协议网关帧计数">
                    <a-input v-model="form.workingData15" />
                  </a-form-model-item>
                </a-col>
              </a-row>
            </a-row>
          </div>

          <a-form-model-item :wrapper-col="{ span: 14, offset: 22 }" v-if="false">
            <a-button type="primary" @click="onSubmit">全部配置</a-button>
          </a-form-model-item>
        </a-form-model>
        <a-form-model
          :model="form"
          :label-col="labelCol"
          :wrapper-col="wrapperCol"
          v-if="selectDevice.includes('feedBaseband')"
        >
          <div style="width: 100%; height: 340px; overflow-y: scroll">
            <a-row style="">
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="设备序列号">
                    <a-input v-model="form.workingData1" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="电压">
                    <div style="display: flex; align-items: center">
                      <a-input style="width: 100%" v-model="form.workingData2" suffix="V" />
                      <!-- <span> V </span> -->
                    </div>
                  </a-form-model-item>
                </a-col>
              </a-row>

              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行接收功率">
                    <a-input v-model="form.workingData4" suffix="dBm" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行信噪比">
                    <a-input v-model="form.workingData5" suffix="dB" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行速率">
                    <a-input v-model="form.workingData6" suffix="bps" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行 Eb/N0">
                    <a-input v-model="form.workingData7" suffix="dB" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行自动调制编码">
                    <a-input v-model="form.workingData3" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行载波同步">
                    <a-input v-model="form.workingData8" />
                  </a-form-model-item>
                </a-col>
              </a-row>
            </a-row>
            <a-row style="">
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行位同步">
                    <a-input v-model="form.workingData9" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行帧同步">
                    <a-input v-model="form.workingData10" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行链路状态">
                    <a-input v-model="form.workingData11" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="上行发送帧计数">
                    <a-input v-model="form.workingData12" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行接收帧计数">
                    <a-input v-model="form.workingData13" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="接收协议网关帧计数">
                    <a-input v-model="form.workingData14" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="发射协议网关帧计数">
                    <a-input v-model="form.workingData15" />
                  </a-form-model-item>
                </a-col>
              </a-row>
            </a-row>
          </div>

          <a-form-model-item :wrapper-col="{ span: 14, offset: 22 }" v-if="false">
            <a-button type="primary" @click="onSubmit">全部配置</a-button>
            <!-- <a-button style="margin-left: 10px"> Cancel </a-button> -->
          </a-form-model-item>
        </a-form-model>
        <a-form-model
          :model="form"
          :label-col="labelCol"
          :wrapper-col="wrapperCol"
          v-if="selectDevice.includes('QBandDownconverter')"
        >
          <a-row>
            <div style="width: 100%; height: 340px; overflow-y: scroll">
              <a-row style="">
                <a-row>
                  <a-col :span="24">
                    <a-form-model-item label="当前下变频器温度">
                      <a-input v-model="form.workingDataQ1" />
                    </a-form-model-item>
                  </a-col>
                </a-row>
                <a-row>
                  <a-col :span="24">
                    <a-form-model-item label="当前下变频器增益">
                      <a-table
                        rowKey="id"
                        :columns="workingDataQ2Columns"
                        size="small"
                        :data-source="form.workingDataQ2"
                        :pagination="false"
                        bordered
                      >
                      </a-table>
                    </a-form-model-item>
                  </a-col>
                </a-row>
                <a-row>
                  <a-col :span="24">
                    <a-form-model-item label="当前下变频器本振偏移量">
                      <a-table
                        rowKey="id"
                        :columns="workingDataQ3Columns"
                        size="small"
                        :data-source="form.workingDataQ3"
                        :pagination="false"
                        bordered
                      >
                      </a-table>
                    </a-form-model-item>
                  </a-col>
                </a-row>
                <a-row>
                  <a-col :span="24">
                    <a-form-model-item label="当前下变频器状态">
                      <a-table
                        rowKey="id"
                        :columns="workingDataQ4Columns"
                        size="small"
                        :data-source="form.workingDataQ4"
                        :pagination="false"
                        bordered
                      >
                      </a-table>
                    </a-form-model-item>
                  </a-col>
                </a-row>
              </a-row>
              <a-row style="">
                <a-row>
                  <a-col :span="24">
                    <a-form-model-item label="当前电压">
                      <a-input v-model="form.workingDataQ5" />
                    </a-form-model-item>
                  </a-col>
                </a-row>
                <a-row>
                  <a-col :span="24">
                    <a-form-model-item label="当前电流">
                      <a-input v-model="form.workingDataQ6" />
                    </a-form-model-item>
                  </a-col>
                </a-row>
                <a-row>
                  <a-col :span="24">
                    <a-form-model-item label="通路开关状态">
                      <a-table
                        rowKey="id"
                        :columns="workingDataQ7Columns"
                        size="small"
                        :data-source="form.workingDataQ7"
                        :pagination="false"
                        bordered
                      >
                        <span slot="gain" slot-scope="text">{{ text == 1 ? '开' : '关' }}</span>
                      </a-table>
                    </a-form-model-item>
                  </a-col>
                </a-row>
                <a-row>
                  <a-col :span="24">
                    <a-form-model-item label="输出功率">
                      <a-table
                        rowKey="id"
                        :columns="workingDataQ9Columns"
                        size="small"
                        :data-source="form.workingDataQ9"
                        :pagination="false"
                        bordered
                      >
                      </a-table>
                    </a-form-model-item>
                  </a-col>
                </a-row>
                <a-row>
                  <a-col :span="24">
                    <a-form-model-item label="终端序列号">
                      <a-input v-model="form.workingDataQ8" />
                    </a-form-model-item>
                  </a-col>
                </a-row>
              </a-row>
            </div>
          </a-row>
        </a-form-model>
        <a-table
          v-if="selectDevice.includes('switchMatrix')"
          :columns="columns"
          rowKey="id"
          :scroll="{ y: 300 }"
          size="small"
          :data-source="data"
          bordered
        >
          <span slot="name" slot-scope="text">{{ text }}</span>
        </a-table>
        <a-table
          v-if="selectDevice.includes('ProtocolGateway')"
          :columns="columns1"
          rowKey="id"
          size="small"
          :scroll="{ y: 300 }"
          :data-source="data1"
          bordered
        >
          <span slot="name" slot-scope="text">{{ text }}</span>
        </a-table>
        <a-form-model
          :model="form"
          :label-col="labelCol"
          :wrapper-col="wrapperCol"
          v-if="sctiveType == 'VBandUpconverter'"
        >
          <div style="width: 100%; height: 340px; overflow-y: scroll" v-if="selectDevice.includes('VBandUpconverter')">
            <a-row style="">
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="当前上变频器温度">
                    <a-input v-model="form.workingDataV1" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="当前上变频器增益">
                    <a-table
                      rowKey="id"
                      :columns="workingDataV2Columns"
                      size="small"
                      :data-source="form.workingDataV2"
                      :pagination="false"
                      bordered
                    >
                    </a-table>
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="当前上变频器本振偏移量">
                    <a-table
                      rowKey="id"
                      :columns="workingDataV3Columns"
                      size="small"
                      :data-source="form.workingDataV3"
                      :pagination="false"
                      bordered
                    >
                    </a-table>
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="当前上变频器状态">
                    <a-table
                      rowKey="id"
                      :columns="workingDataV4Columns"
                      size="small"
                      :data-source="form.workingDataV4"
                      :pagination="false"
                      bordered
                    >
                    </a-table>
                  </a-form-model-item>
                </a-col>
              </a-row>
            </a-row>
            <a-row style="">
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="当前电压">
                    <a-input v-model="form.workingDataV5" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="当前电流">
                    <a-input v-model="form.workingDataV6" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="通路开关状态">
                    <a-table
                      rowKey="id"
                      :columns="workingDataV7Columns"
                      size="small"
                      :data-source="form.workingDataV7"
                      :pagination="false"
                      bordered
                    >
                      <span slot="gain" slot-scope="text">{{ text == 1 ? '开' : '关' }}</span>
                    </a-table>
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="终端序列号">
                    <a-input v-model="form.workingDataV8" />
                  </a-form-model-item>
                </a-col>
              </a-row>
            </a-row>
          </div>
        </a-form-model>
            <a-form-model
          :model="form"
          :label-col="labelCol"
          :wrapper-col="wrapperCol"
          v-if="sctiveType == 'commone'"
        >
          <div style="width: 100%; height: 340px; " v-if="selectDevice.includes('commone')">
            <a-row style="">
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="载荷ID">
                    <a-input v-model="form.LoadID" />
                  </a-form-model-item>
                </a-col>
              </a-row>
            </a-row>
            <a-row style="">
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="上行同步状态">
                    <a-input v-model="form.StatuUp" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="下行同步状态">
                    <a-input v-model="form.StatuDown" />
                  </a-form-model-item>
                </a-col>
              </a-row>

              <a-row>
                <a-col :span="24">
                  <a-form-model-item label="上行误码率">
                    <a-input v-model="form.UplinkErrorRate" />
                  </a-form-model-item>
                </a-col>
                <a-col :span="24">
                  <a-form-model-item label="下行误码率">
                    <a-input v-model="form.DownlinkErrorRate" />
                  </a-form-model-item>
                </a-col>
              </a-row>
            </a-row>
          </div>
        </a-form-model>
      </a-collapse-panel>
    </a-collapse>
  </div>
</template>

<script>
import analysisWorkData from './analysisWorkData'
import { httpAction, getAction } from '@api/manage'
export default {
  mixins: [analysisWorkData],
  data() {
    return {
      sctiveType: 'feedBaseband',
      deviceData: {},
      activeKey: '1',
      deviceList: [],
      selectDevice: 'feedBaseband-8a329ea67d7e402a81145ef09e3ea682',
      form1: {},
      labelCol: { span: 8 },
      wrapperCol: { span: 12 },
      labelCol1: { span: 4 },
      wrapperCol1: { span: 14 },
      data: [],
      data1: [],
      columns: [
        {
          title: '输出通道',
          dataIndex: 'enter',
          key: 'enter',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '输入通道',
          dataIndex: 'outputState',
          key: 'outputState',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '通道功率',
          dataIndex: 'power',
          key: 'power',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '饱和状态',
          dataIndex: 'saturateState',
          key: 'saturateState',
          ellipsis: true,
          align: 'center',
        },
      ],
      columns1: [
        {
          title: '天线编号',
          dataIndex: 'antenna',
          key: 'antenna',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '馈电通道',
          dataIndex: 'passage',
          key: 'passage',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '调制IP地址',
          dataIndex: 'modulationIp',
          key: 'modulationIp',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '解调IP地址',
          dataIndex: 'demodulationIp',
          key: 'demodulationIp',
          ellipsis: true,
          align: 'center',
        },
      ],
      num: 1,
      form: {
        workingData1: '',
        workingData2: '',
        workingData3: '',
        workingData4: '',
        workingData5: '',
        workingData6: '',
        workingData7: '',
        workingData8: '',
        workingData9: '',
        workingData10: '',
        workingData11: '',
        workingData12: '',
        workingData13: '',
        workingData14: '',
        workingData15: '',
      },
    }
  },
  watch: {
    form(A, B) {
      console.log(A, B, 'data11111')
    },
  },
  created() {
    // setInterval(()=>{
    // this.getDeviceData()
    // this.getDeviceList()
    // },2000)
  },
  methods: {
    handleChange(value, a, b) {
      this.form = {}
      // this.form1 = {}
      this.data = []
      this.data1 = []
      // this.getDeviceDataByTopologyInstId(value)
      let select = this.deviceList.find((i) => i.topologyInstId == value)
      console.log(select, 'select')
      this.sctiveType = select ? select.topologyInstType : ''
    },
    getDeviceList() {
      getAction('/device/dmDevice/list', {
        pageSize: '-1',
      }).then((res) => {
        if (res.success) {
          // console.log(res, 'res')
          this.deviceList = res.result.records || {}
          // this.getWorkingData()
        } else {
          this.$message.error(res.message)
        }
      })
    },
    getDeviceDataByTopologyInstId(InstId) {
      getAction('/device/dmDevice/getByTopologyInstId', {
        topologyInstId: InstId,
      }).then((res) => {
        if (res.success) {
          this.deviceData = res.result || {}
          this.getWorkingData()
        } else {
          this.$message.error(res.message)
        }
      })
    },
    getDeviceData() {
      getAction('/device/dmDevice/getByTopologyInstId', {
        topologyInstId: 'feedBaseband-8a329ea67d7e402a81145ef09e3ea682',
      }).then((res) => {
        if (res.success) {
          this.deviceData = res.result || {}
          this.getWorkingData()
        } else {
          this.$message.error(res.message)
        }
      })
    },
  },
}
</script>
<style scoped lang="less">
.txt-box {
  display: flex;
  font-size: 13px;
  .left {
    width: 120px;
    text-align: right;
    margin-right: 10px;
    color: #909399;
  }
}
</style>
